package com.tuo51.manager.controller;


import com.tuo51.foudation.model.MemVerificationCache;
import com.tuo51.foudation.model.StatusResponse;
import com.tuo51.manager.service.DataAnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.tuo51.foudation.constant.RequestConstant.TICKET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

@RestController
@RequestMapping("/mapi/analysis")
@Api(value = "/mapi/analysis", tags = "OP - 数据分析")
public class MAPIAnalysisController {

    @Autowired
    DataAnalysisService analysisService;

    @Autowired
    MemVerificationCache cache;

    @RequestMapping(value = "/general_info", method = POST)
    @ApiOperation("常规统计信息")
    public StatusResponse generalAnalysis(@RequestHeader(TICKET) String ticket){
        String staffId = cache.getStaffId(ticket);

        List result = analysisService.getFullReports();

        return StatusResponse.success(result);
    }

    @RequestMapping(value = "/report_trending", method = POST)
    @ApiOperation("报告统计趋势")
    public StatusResponse reportsTrending(@RequestHeader(TICKET) String ticket,
                                          @RequestParam(value = "type", defaultValue = "0", required = false) Integer type){
        String staffId = cache.getStaffId(ticket);
        return StatusResponse.success(analysisService.getSystemRecordCounts(type));
    }

    @RequestMapping(value = "/user_trending", method = POST)
    @ApiOperation("用户新增统计趋势")
    public StatusResponse userTrending(@RequestHeader(TICKET) String ticket,
                                       @RequestParam(value = "type", defaultValue = "0", required = false) Integer type){
        String staffId = cache.getStaffId(ticket);
        return StatusResponse.success(analysisService.getSystemUserCounts(type));
    }

    @RequestMapping(value = "/location_trending", method = POST)
    @ApiOperation("用户地理位置趋势")
    public StatusResponse locationTrending(@RequestHeader(TICKET) String ticket){
        String staffId = cache.getStaffId(ticket);
        return StatusResponse.success(analysisService.getSystemLocationCounts());
    }
}
